#include "Acceptor.h"
#include "TcpConnection.h"
#include "EventLoop.h"
#include <iostream>
using std::endl;
using std::cout;
void onConnection(TcpConnectionPtr conn)
{
    cout << conn->toString() << "has connected" << endl;

}
void onMessage(TcpConnectionPtr conn)
{
    string msg = conn->recv();
    cout << "recv msg: " << msg << endl;
    //decode
    //compute
    //encode
    conn->send(msg);
}

void onClose(TcpConnectionPtr conn)
{
    cout << conn->toString() << "has closed" << endl;

}
int main(int argc, char *argv[])
{
    Acceptor acceptor(8080);
    acceptor.ready();
    EventLoop loop(acceptor);
    loop.setAllCallbacks(onClose, onMessage, onConnection);
    loop.loop();
    return 0;
}

